package com.sunnada.weixin.util.weixinPay;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import com.sunnada.weixin.util.weixinPay.LoadConfig;
import com.sunnada.weixin.util.weixinPay.StrUtil;

/**
 * 
 * @Title:常量
 * @author     liudd     2015-07-02
 */
public class Constant {
	private static String CONFIG_FILENAME = "/constant.ini";
	private static Properties CONSTANT_PROPERTIES = LoadConfig.getConfigFromPath(CONFIG_FILENAME);
	
	
	//文件上传配置参数
	public static final class IMAGE{
		//图片上传
		public static final String IMAGES_FILE_URL=CONSTANT_PROPERTIES.getProperty("IMAGES_FILE_URL");
		//图片压缩
		public static final double IMAGES_COMBASE=Double.parseDouble(CONSTANT_PROPERTIES.getProperty("IMAGES_COMBASE"));//压缩基数
		public static final double IMAGES_SACLE=Double.parseDouble(CONSTANT_PROPERTIES.getProperty("IMAGES_SACLE"));//压缩限制(宽/高)比例 
	}
	//微信基础信息配置
	public static final class WEIXIN{
		public static final String WX_URL=CONSTANT_PROPERTIES.getProperty("WX_URL");
		public static final String TOKEN = CONSTANT_PROPERTIES.getProperty("TOKEN");
		public static final String APP_ID = CONSTANT_PROPERTIES.getProperty("WX_APP_ID");
		public static final String SECRET = CONSTANT_PROPERTIES.getProperty("WX_APP_SECRET");
		public static final String MCH_ID = CONSTANT_PROPERTIES.getProperty("MCH_ID");
		public static final String MCH_KEY = CONSTANT_PROPERTIES.getProperty("MCH_KEY");
		public static int ORDER_TIMEOUT_SECOND =StrUtil.getNotNullIntValue(CONSTANT_PROPERTIES.getProperty("ORDER_TIMEOUT_SECOND"), 600) ;
		public static int CONNECT_TIMEOUT = StrUtil.getNotNullIntValue(CONSTANT_PROPERTIES.getProperty("connect_timeout"), 60 * 1000) ;
		public static int READ_TIMEOUT = StrUtil.getNotNullIntValue(CONSTANT_PROPERTIES.getProperty("read_timeout"), 60 * 1000) ;
		public static String ACCESS_TOKEN = "";
		public static String JSAPI_TICKET = "";
		public static String SNS_OAUTH2_ASSESS_TOKEN = "";
	}
	
	//微信APP基础信息配置
	public static final class WEIXINAPP{
		public static final String APP_ID = CONSTANT_PROPERTIES.getProperty("WXAPP_APP_ID");
		public static final String SECRET = CONSTANT_PROPERTIES.getProperty("WXAPP_APP_SECRET");
		public static final String MCH_ID = CONSTANT_PROPERTIES.getProperty("MCHAPP_ID");
		public static final String MCH_KEY = CONSTANT_PROPERTIES.getProperty("MCHAPP_KEY");
	}
	
	
	//微信调用地址群
	public static final class URL {
		public static final String ACCESS_TOKEN_URL = CONSTANT_PROPERTIES.getProperty("url_assess_token");
		public static final String USER_INFO = CONSTANT_PROPERTIES.getProperty("url_user_info");
		public static final String QRCODE_CREATE = CONSTANT_PROPERTIES.getProperty("url_qrcode_create");
		public static final String SHOWQRCODE = CONSTANT_PROPERTIES.getProperty("url_showqrcode");
		public static final String QRCODE_BASE = CONSTANT_PROPERTIES.getProperty("url_qrcode_base");
		public static final String MEDIA_UPLOAD = CONSTANT_PROPERTIES.getProperty("url_media_upload");
		public static final String JSAPI_TICKET = CONSTANT_PROPERTIES.getProperty("url_jsapi_ticket");
		public static final String PAY_UNIFIEDORDER =CONSTANT_PROPERTIES.getProperty("url_pay_unifiedorder");
		public static final String PAY_CARDORDER =CONSTANT_PROPERTIES.getProperty("url_pay_cardorder");
		public static final String PAY_REFUNDORDER =CONSTANT_PROPERTIES.getProperty("url_pay_refundorder");
		public static final String PAY_ORDERQUERY =CONSTANT_PROPERTIES.getProperty("url_pay_orderquery");
		public static final String PAY_NOTIFY = CONSTANT_PROPERTIES.getProperty("url_pay_notify");
		public static final String SNS_OAUTH2_ASSESS_TOKEN = CONSTANT_PROPERTIES.getProperty("url_sns_oauth2_assess_token");
		public static final String GETUSERINFO = CONSTANT_PROPERTIES.getProperty("url_getuserinfo");
		public static final String CURRENT_URL = CONSTANT_PROPERTIES.getProperty("url_current_url");
	}
	
	//微信基础信息配置
		public static final class CARD{
			public static final String READCARD_IP=CONSTANT_PROPERTIES.getProperty("READCARD_IP");
			public static final String READCARD_PORT = CONSTANT_PROPERTIES.getProperty("READCARD_PORT");
		}
		
	//BS js及css版本控制
	public static final String VERSION_TYPE=CONSTANT_PROPERTIES.getProperty("VERSION_TYPE");
	public static final String VERSION_ID=CONSTANT_PROPERTIES.getProperty("VERSION_ID");
	public static String VERSION_IDSYS= "" ;	
	//读取中文配置专用
	public static String getSysVersion(){
		if("".equals(VERSION_IDSYS)){
			VERSION_IDSYS = new SimpleDateFormat("yyMMddHHmmss").format(new Date());
		}
		return VERSION_IDSYS;
	}
	//读取中文配置专用
	public static String trans(String str){
		String ret="";
		try {
			ret= new String(str.getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			System.out.println("读取中文参数进行转化出错,出错信息:"+e.getMessage());
		}
		return ret;
	}
	
}
